{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "27647085-e887-44b3-82cc-fa01dc66bf8c",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/swap-nodes-in-pairs\n",
    "\n",
    "\n",
    "Runtime: 4 ms, faster than 61.94% of C++ online submissions for Swap Nodes in Pairs.\n",
    "Memory Usage: 7.7 MB, less than 49.30% of C++ online submissions for Swap Nodes in Pairs.\n",
    "\n",
    "\n",
    "```cpp\n",
    "class Solution {\n",
    "public:\n",
    "    vector<ListNode*> list1;\n",
    "    vector<ListNode*> list2;\n",
    "    ListNode* swapPairs(ListNode* head) {\n",
    "      //7:10\n",
    "      list1.clear();\n",
    "      list2.clear();\n",
    "      auto node = head;\n",
    "      while (node != nullptr) {\n",
    "        list1.push_back(node);\n",
    "        node = node->next;\n",
    "      }\n",
    "      if (list1.size()==0) {\n",
    "        return nullptr;\n",
    "      }\n",
    "      for (int i=0; i < list1.size(); i++) {\n",
    "        if (i % 2 != 0) {\n",
    "          list2.insert(list2.end()-1, list1[i]);\n",
    "        } else {\n",
    "          list2.push_back(list1[i]);\n",
    "        }\n",
    "      }\n",
    "      for (int i=0; i < list2.size(); i++) {\n",
    "        if (i != list2.size()-1) {\n",
    "          list2[i]->next = list2[i+1];\n",
    "        } else {\n",
    "          list2[i]->next = nullptr;\n",
    "        }\n",
    "      }\n",
    "      return list2[0];\n",
    "      //7:17\n",
    "      //debug until 7:20\n",
    "    }\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5000dac-7571-4fcc-8942-b4b4731eb3b7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "name": ""
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
